# import the necessary packages
import argparse
import imutils
import cv2 as cv

# consturct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="The Path To Image")
args = vars(ap.parse_args())

# load the image and show it
image = cv.imread(args["image"])
cv.imshow("Original", image)

# we need to keep in mind aspect ratio so the image does not look skewed
# or distored -- therefore, we calculate the ratio of the new image to
# the old image.Let's make our new image have a width of 150 pixels
r = 150.0 / image.shape[1]
dim = (150, int(image.shape[0] * r))

# perform the actual resizing of the image
resized = cv.resize(image, dim, interpolation=cv.INTER_AREA)
cv.imshow("Resized (Width)", resized)
cv.waitKey(0)
# what if we wanted to adjust the height of the image? We can apply
# the same concept,again keeping in mind the aspect ratio,but instead
# calculating the ratio based on height -- let's maek the height of the
# resizeed image 50 pixels
r = 50.0 / image.shape[0]
dim = (int(image.shape[1] * r), 50)

# perform the resizing
resized = cv.resize(image, dim, interpolation=cv.INTER_AREA)
cv.imshow("Resized (Height)", resized)
cv.waitKey(0)

# of course,calculating the ratio each and every time we want to resize
# an image is a real pain -- let's create a function where we can sepcify
# our target width or height ,and have it take care of the reset for us.
resized = imutils.resize(image, width=100)
cv.imshow("Resizeed via Function", resized)
cv.waitKey(0)

# construct the list of the interpolation methods
methods = [
    ("cv2.INTER_NEAREST",cv.INTER_NEAREST),
    ("cv2.INTER_LINERA",cv.INTER_LINEAR),
    ("cv2.INTER_AREA",cv.INTER_AREA),
    ("cv2.INTER_CUBIC",cv.INTER_CUBIC),
    ("cv2.INTER_LANCZOS4",cv.INTER_LANCZOS4)
]
# loop over the interpolation methods
for (name,method) in methods:
    # increase the size of the image by 3x using the current interpolation
    # method
    resized = imutils.resize(image,width=image.shape[1] * 3,inter=method)
    cv.imshow("Method: {}".format(name),resized)
    cv.waitKey(0)
